<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <div>编号：{{stu.code}}</div>
        <div>姓名：{{stu.name}}</div>
        <div>分数：{{stu.score}}</div>
        <button ng-click="reset()">重置</button>
    </div>
    <div ng-controller="cont_2">
        <div>编号：{{stu.code}}</div>
        <div>姓名：{{stu.name}}</div>
        <div>分数：{{stu.score}}</div>
    </div>

    <script>
        function student(json) {
            angular.extend(this,json);
            this.reset = function () {
                this.code = 1000;
                this.name = "张三";
                this.score = 0;
            }
        }
        student.create = function () {
            return new student({
                code:1001,
                name:"往下",
                score:99
            })
        }
        angular.module('app',[])
            .factory('$student',function () {
                return {
                    create:student.create
                }
            })
            .controller('cont',function ($scope,$student) {
                $scope.stu = $student.create();
                $scope.reset = function () {
                    $scope.stu.reset();
                }
            })
            .controller('cont_2',function ($scope,$student) {
                $scope.stu = $student.create();
            })

    </script>
</body>
</html>